﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using StackExchangeRedis;

namespace RedisWebApplication.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Admin()
        {
            ViewBag.type = "admin";
           

            return View("Index");
        }
        public ActionResult Gust()
        {
            ViewBag.type = "gust";
          
            return View("Index");
        }

        public ActionResult SendMessage(string message, string type)
        {
            var _redisHelper = new RedisHelper();
            _redisHelper.Publish(type, message);
            return Json("发送成功");
        }

        public ActionResult GetMessList(string type)
        {
            var _redisHelper = new RedisHelper();
            var messlist = new List<string>();
            _redisHelper.Subscribe(type, (channel, message) =>
            {
                messlist.Add($"我收到来自{type}发布的消息为：{message}");
            });
            return Json(messlist, JsonRequestBehavior.AllowGet);
        }
    }
}